package com.badshun.util;

import com.badshun.player.*;

public class BadMap<K extends String,V extends NPCPlayer> {
	private String[] keyList;
	private BadList valueList;
	private int index;
	
	public BadMap() {
		keyList = new String[1024];
		valueList = new BadList();
		
		index = 0;
	}
	
	public boolean putChild(String key,NPCPlayer value) {
		for(int i = 0; i < getLength(); i++) {
			if(key.equals(keyList[i])) {
				return false;
			}
		}
		
		keyList[index] = key;
		valueList.addChild(value);
		
		index++;
		
		return true;
	}
	
	public NPCPlayer getValue(String key) {
		for(int i = 0; i < getLength(); i++) {
			if(key.equals(keyList[i])) {
				return valueList.getChild(i);
			}
		}
		
		return null;
	}
	
	public NPCPlayer removeValue(String key) {
		for(int i = 0; i < getLength(); i++) {
			if(key.equals(keyList[i])) {
				valueList.removeChild(i);
				return valueList.getChild(i);
			}
		}

		return null;
	}
	
	public int getLength() {
		return index;
	}
}
